From BlenderWiki

Jump to: navigation, search
Note: This is an archived version of the Blender Developer Wiki. The current and active wiki is available on wiki.blender.org.

Hi Ideasman,

I am trying to determine if BlenderAsPyModule can help me. I recently asked a question on the Blenderartists forum and was directed to you. Thread: http://blenderartists.org/forum/showthread.php?285894-Integrating-Blender-into-scripting-languages-e-g-Python-Matlab.

I would like to call Blender from a Matlab script. Ideally, I would like to think of my call to Blender as being not-so-different from my call to any other function. e.g. I would like to be able to write a wrapper that would give me a syntax like: image = Blender(args). Which would mean "call blender with args and return the rendered image".

I know how to run Blender from Matlab---e.g., with !blender -b file.blend -P render.py. This works well for some things, but there are some big limitations. For one, you can't keep Blender running and waiting for new commands like you would if, say, you wanted to render a sequence of images of an object viewed from different angles. Another problem (less critical) is that this way of calling Blender does not directly return an image to Matlab; the only way to get the image is to have Blender save it to a particular location where Matlab knows to look for it.

I am wondering if BlenderAsPyModule would allow me to solve both of these problems with a Python script---which I could then put a Matlab wrapper around. I believe Python has all the multitasking features that I would want for this solution. I've never tried using Python in this way before, but it ought to be possible to have a python script wait for commands from Matlab. So, as long as BlenderAsPyModule solves the problem of getting Blender to wait for outside commands then I should be able to get the whole thing to work.

What do you think? Would BlenderAsPyModule work for this?

Also, someone in the BlenderArtists forum mentioned that many of Blender's features are still unavailable with BlenderAsPyModule. On your page I only see that it is restricted to features that are usable in background mode. Is that what they were referring to? If so, that's fine for me, I only need background mode.